package models;

/**
 * A Subscription object represents a subscription of a client for a workshop.
 */
public class Subscription extends DatabaseModel {
	private Client client;
	private Workshop workshop;
	
	/**
	 * Create an empty subscription.
	 */
	public Subscription() {
	}
	
	/**
	 * Create a subscription of client for workshop.
	 * 
	 * @param client to subscribe
	 * @param workshop to subscribe for
	 */
	public Subscription(Client client, Workshop workshop) {
		this.client = client;
		this.workshop = workshop;
	}
	
	/**
	 * Same as {@link #Subscription(Client, Workshop)}, but with the ID added.
	 */
	public Subscription(int id, Client client, Workshop workshop) {
		this(client, workshop);
		setId(id);
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public String[] getData() {
		String[] data = { "" + this.client.getId(), "" + this.workshop.getId()};
		return data;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String[] getDataHeaders() {
		String[] headers = {"client", "workshop"};
		return headers;
	}
	
	public Client getClient() {
		return client;
	}
	
	public void setClient(Client client) {
		this.client = client;		
	}

	public Workshop getWorkshop() {
		return workshop;
	}
	
	public void setWorkshop(Workshop workshop) {
		this.workshop = workshop;		
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((client == null) ? 0 : client.hashCode());
		result = prime * result
				+ ((workshop == null) ? 0 : workshop.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		Subscription other = (Subscription) obj;
		if (client == null) {
			if (other.client != null)
				return false;
		} else if (!client.equals(other.client))
			return false;
		if (workshop == null) {
			if (other.workshop != null)
				return false;
		} else if (!workshop.equals(other.workshop))
			return false;
		return true;
	}
	
}
